/*
 * Powered By xTOOLs
 * Dev by tao.li8@pactera.com
 * Copyright ©2009-2018 pactera.com All rights reserved.
 *
 * Generated at Jan 12, 2021 10:10:47 AM
 */

package com.pactera.jep.service.sys.service.impl;

import com.pactera.jep.orm.Page;
import com.pactera.jep.orm.mybatis.helper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pactera.jep.orm.mybatis.mapper.Mapper;
import com.pactera.jep.orm.mybatis.service.MyBatisCRUDService;

import com.pactera.jep.service.sys.mapper.DeviceLoginMapper;
import com.pactera.jep.service.sys.service.DeviceLoginService;
import com.pactera.jep.service.sys.model.DeviceLogin;

import java.util.Date;
import java.util.List;

/**
 * 服务层实现
 * @author YourName
 * @date Jan 12, 2021 10:10:47 AM
 */
@Service
@Transactional(readOnly = false)
public class DeviceLoginServiceImpl extends MyBatisCRUDService<DeviceLogin, String> implements DeviceLoginService {

    Logger logger =  LoggerFactory.getLogger(getClass());

    @Autowired
    private DeviceLoginMapper			deviceLoginMapper;

    @Override
    public Mapper<DeviceLogin, String> getMapper() {
         return deviceLoginMapper;
    }

    @Override
    public void increase(DeviceLogin deviceLogin) {
        DeviceLogin deviceLogin1 = deviceLoginMapper.selectOne(deviceLogin);
        if(deviceLogin1 == null) {
            deviceLogin.setLoginTime(new Date());
            deviceLoginMapper.insert(deviceLogin);
        } else {
//            long l = System.currentTimeMillis();
            deviceLogin1.setLoginTime(new Date());
            deviceLoginMapper.update(deviceLogin1);
        }
    }

    @Override
    public Page<DeviceLogin> queryAll(Page page, DeviceLogin deviceLogin) {
        List<DeviceLogin> deviceLoginList = deviceLoginMapper.queryAll(deviceLogin);
        PageHelper.start(page);
        PageHelper.end(page, deviceLoginList);
        return page;
    }
}
